package com.itheima.service.impl;


import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.itheima.mapper.StudentsMapper;
import com.itheima.pojo.Clazz;
import com.itheima.pojo.PageResult;
import com.itheima.pojo.Student;
import com.itheima.service.StudentsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

@Service
public class StudentsServiceImpl implements StudentsService {

    @Autowired
    private StudentsMapper studentsMapper;

    @Override
    public PageResult page(String name, Integer degree, Integer clazzId, Integer page, Integer pageSize) {
        PageHelper.startPage(page, pageSize);

        List<Student> dataList = studentsMapper.list(name, degree, clazzId);
        Page<Student> p = (Page<Student>) dataList;

        return new PageResult(p.getTotal(), p.getResult());
    }

    @Override
    public Student getInfo(Integer id) {
        return studentsMapper.getInfo(id);
    }

    @Override
    public void update(Student student) {
        student.setUpdateTime(LocalDateTime.now());
        studentsMapper.update(student);
    }

    @Override
    public void deduct(Integer id, Integer score) {
        studentsMapper.deduct(id, score);
    }

    @Override
    public void add(Student student) {
        student.setUpdateTime(LocalDateTime.now());
        student.setCreateTime(LocalDateTime.now());
        studentsMapper.add(student);
    }

    @Override
    public void delete(List<Integer> ids) {
        studentsMapper.delete(ids);
    }
}
